package com.qixiucoding.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @Description 获取json配置类
 * @Author longhj
 * @Date 2021/11/20 星期六 23:27
 */
@Component
@Slf4j
@ConditionalOnProperty(prefix = "json",name = "configName",havingValue = ".*json",matchIfMissing = false)
public class JSONConfigManager {

    @Autowired
    private JSONConfiguration jsonConfiguration;
    private JSONProperty jsonProperty;

    public JSONProperty getJsonProperty() {
        return this.jsonProperty;
    }

    private void setJsonProperty(JSONProperty jsonProperty) {
        this.jsonProperty = jsonProperty;
    }

    @PostConstruct
    public void init() {
        String s = JSONHelper.ResolveJsonFileToString(jsonConfiguration.getConfigName());
        System.out.println("sss=" + s);

        Map map = (Map) JSONHelper.resolveJsonFileToObject(jsonConfiguration.getConfigName());
        System.out.println("name=" + map.get("name"));
        JSONProperty myJson = JSONHelper.resolveJsonFileToJsonObject(jsonConfiguration.getConfigName(), JSONProperty.class);
        System.out.println("myJson=" + myJson.toString());
        setJsonProperty(myJson);
        System.out.println(jsonProperty.toString());

    }
}
